package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.search.SearchFeignClient;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

/**
 * @author lfy
 * @Description 检索服务页面跳转控制
 * @create 2023-07-24 9:04
 */
@Controller
public class ListController {


    @Autowired
    SearchFeignClient searchFeignClient;
    /**
     * 使用对象vo：统一封装请求携带来的 k=v 类型的参数；
     * @RequestBody：统一封装请求带来的 json 数据
     *
     * @param   searchParamVo
     * @return
     */
    @GetMapping("/list.html")
    public String list(SearchParamVo searchParamVo,
                       Model model){

        //1、远程要什么、我要什么
        Result<Map<String, Object>> search = searchFeignClient.search(searchParamVo);
        Map<String, Object> data = search.getData();
        //把返回的map的所有数据全部交给页面
        model.addAllAttributes(data);


        return "list/index";
    }
}
